Conditions | 3 |
Total Lines | 13 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import cottus, { ValidationError } from 'cottus'; |
||
4 | export function validate(data, rules) { |
||
5 | const validator = cottus.compile([ 'required', { 'attributes': rules } ]); |
||
6 | |||
7 | try { |
||
8 | return validator.validate(data); |
||
9 | } catch (error) { |
||
10 | if (error instanceof ValidationError) { |
||
11 | throw new VALIDATION_FAILED(error); |
||
12 | } |
||
13 | |||
14 | throw error; |
||
15 | } |
||
16 | } |
||
17 |